﻿using System;

using Sustainalytics.Entities;
using Sustainalytics.LongRunningTaskManager.Interface;
using Sustainalytics.Portfolios.BL;

namespace Sustainalytics.Portfolios.Service.Models
{
    public class PortfolioUploadDto : FileManagerFileTaskParam
    {
        public string PortfolioId { get; set; }
        public string PortfolioName { get; set; }
        public string AccountId { get; set; }
        public string UserId { get; set; }
        public int SharingStatus { get; set; }
        public DateTime InsertDate { get; set; }
    }


    public static class PortfolioUploadExtension
    {
        //todo refactor typesafety
        public static PortfolioUpload ToDto(this PortfolioUploadDto portfolioDto)
        {
            return new PortfolioUpload
            {
                AccountId = new Guid(portfolioDto.AccountId),
                InsertDate = portfolioDto.InsertDate,
                PortfolioId = !string.IsNullOrEmpty(portfolioDto.PortfolioId) ? new Guid(portfolioDto.PortfolioId) : Guid.NewGuid(),
                PortfolioName = portfolioDto.PortfolioName,
                SharingStatus = portfolioDto.SharingStatus == 1 ? PortfolioSharingStatus.Private : PortfolioSharingStatus.Shared,
                UserId = new Guid(portfolioDto.UserId)
            };
        }
    }
}
